package club.dataresources.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间和日期转换帮助类
 *
 * @author
 * @create 2018-01-26 14:54
 **/
public class TimeAndDateUtil {

    public static Date getDateFromMonth(String string) {
        String str = "yyyy-MM";
        SimpleDateFormat sdf = new SimpleDateFormat(str);
        Date date = new Date();
        try {
            date = sdf.parse(string);
        } catch (Exception e) {
            e.getStackTrace();
        }
        return date;
    }

    public static Date getDateFromDay(String time) throws ParseException {
        String str = "yyyy-MM-dd";
        SimpleDateFormat sdf = new SimpleDateFormat(str);
        Date date = new Date();
        try{
            date = sdf.parse(time);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }

    public static Date getDateFromYear(String time) throws ParseException {
        String str = "yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(str);
        Date date = new Date();
        try{
            date = sdf.parse(time);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }
}
